﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace Abhiruchi_Phase1.BAL_DAL.ORG_DAL
{
    public class ORGTaskMappingMasterDAL
    {
        public static SqlConnection myCon = new SqlConnection(App.ConnectionString);
        public static SqlCommand myCom;

        public static DataTable GetDBDetails(int processtype)
        {
            
                DataTable mydt = LoadBasicComm();
                myCom.Parameters.AddWithValue("@PType", processtype);
                SqlDataAdapter myadp = new SqlDataAdapter(myCom);
                myadp.Fill(mydt);
                return mydt;

        }
        public static DataTable GetDBDetailsOfTaskName(int processtype,string taskname)
        {

            DataTable mydt = LoadBasicComm();
            myCom.Parameters.AddWithValue("@PType", processtype);
            myCom.Parameters.AddWithValue("@tempTask", taskname);
            SqlDataAdapter myadp = new SqlDataAdapter(myCom);
            myadp.Fill(mydt);
            return mydt;

        }

        public static DataTable GetDBDetails(string empType, int processtype)
        {
            DataTable mydt = LoadBasicComm();
            myCom.Parameters.AddWithValue("@PType", processtype);
            myCom.Parameters.AddWithValue("@EmployeeType", empType);
            SqlDataAdapter myadp = new SqlDataAdapter(myCom);
            myadp.Fill(mydt);
            return mydt;
        }
        public static DataTable InsertDetails(int Section, int Task, string EmployeeType, string Eid, DateTime StartDate, DateTime EndDate, int renew, string Remarks, int active, int PType)
        {
            DataTable mydt = LoadBasicComm();
            myCom.Parameters.AddWithValue("@Section", Section);
            myCom.Parameters.AddWithValue("@Task", Task);
            myCom.Parameters.AddWithValue("@EmployeeType", EmployeeType);
            myCom.Parameters.AddWithValue("@Eid", Eid);
            myCom.Parameters.AddWithValue("@StartDate", StartDate);
            myCom.Parameters.AddWithValue("@EndDate", EndDate);
            myCom.Parameters.AddWithValue("@AutoRenew", renew);
            myCom.Parameters.AddWithValue("@Remarks", Remarks);
            myCom.Parameters.AddWithValue("@IsActive", active);
            myCom.Parameters.AddWithValue("@PType", PType);
            SqlDataAdapter myadp = new SqlDataAdapter(myCom);
            myadp.Fill(mydt);
            return mydt;
        }
        private static DataTable LoadBasicComm()
        {
            DataTable mydt = new DataTable();
            myCom = new SqlCommand();
            myCom.Connection = myCon;
            myCom.CommandText = "SP_ORG_Get_Set_TaskMapping";
            myCom.CommandType = CommandType.StoredProcedure;
            return mydt;
        }

        public static DataTable UpdateAndSelectDetails( int Section, int Task, string EmployeeType, string Eid, DateTime StartDate, DateTime EndDate, int renew, string Remarks, int active, int PType)
        {
            DataTable mydt = LoadBasicComm();            
            myCom.Parameters.AddWithValue("@Section", Section);
            myCom.Parameters.AddWithValue("@Task", Task);
            myCom.Parameters.AddWithValue("@EmployeeType", EmployeeType);
            myCom.Parameters.AddWithValue("@Eid", Eid);
            myCom.Parameters.AddWithValue("@StartDate", StartDate);
            myCom.Parameters.AddWithValue("@EndDate", EndDate);
            myCom.Parameters.AddWithValue("@AutoRenew", renew);
            myCom.Parameters.AddWithValue("@Remarks", Remarks);
            myCom.Parameters.AddWithValue("@IsActive", active);
            myCom.Parameters.AddWithValue("@PType", PType);
            SqlDataAdapter myadp = new SqlDataAdapter(myCom);
            myadp.Fill(mydt);
          
            return mydt;
        }
        public static DataTable UpdateDetails(int Section, int Task, string EmployeeType, string Eid, DateTime StartDate, DateTime EndDate, int renew, string Remarks, int active, int PType)
        {
            DataTable mydt = LoadBasicComm();   
            myCom.Parameters.AddWithValue("@Section", Section);
            myCom.Parameters.AddWithValue("@Task", Task);
            myCom.Parameters.AddWithValue("@EmployeeType", EmployeeType);
            myCom.Parameters.AddWithValue("@Eid", Eid);
            myCom.Parameters.AddWithValue("@StartDate", StartDate);
            myCom.Parameters.AddWithValue("@EndDate", EndDate);
            myCom.Parameters.AddWithValue("@AutoRenew", renew);
            myCom.Parameters.AddWithValue("@Remarks", Remarks);
            myCom.Parameters.AddWithValue("@IsActive", active);
            myCom.Parameters.AddWithValue("@PType", PType);
            myCon.Close();
                myCon.Open();
                myCom.ExecuteNonQuery();
            
            return mydt;
        }

        public static DataTable UpdateAndInsert(int Section, int Task, string Eid, DateTime StartDate, DateTime EndDate, int renew, string Remarks, DateTime CurrentDate, int isactive, int processtype)
        {
            DataTable mydt = new DataTable();
            myCom = new SqlCommand();
            myCom.Connection = myCon;
            myCom.CommandText = "SP_ORG_Get_Set_TaskMappingHistory";

            myCom.Parameters.AddWithValue("@Section", Section);
            myCom.Parameters.AddWithValue("@Task", Task);           
            myCom.Parameters.AddWithValue("@Eid", Eid);
            myCom.Parameters.AddWithValue("@StartDate", StartDate);
            myCom.Parameters.AddWithValue("@EndDate", EndDate);
            myCom.Parameters.AddWithValue("@AutoRenew", renew);
            myCom.Parameters.AddWithValue("@Remarks", Remarks);
            myCom.Parameters.AddWithValue("@ArchivedOn", CurrentDate);
            myCom.Parameters.AddWithValue("@PType", processtype);
            myCom.Parameters.AddWithValue("@IsActive", isactive);
            myCom.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter myadp = new SqlDataAdapter(myCom);
            myadp.Fill(mydt);
            return mydt;
        }
        public static DataTable UpdateAndInsert(string Eid,int processtype)
        {
            DataTable mydt = new DataTable();
            myCom = new SqlCommand();
            myCom.Connection = myCon;
            myCom.CommandText = "SP_ORG_Get_Set_TaskMappingHistory";            
            myCom.Parameters.AddWithValue("@Eid", Eid);        
            myCom.Parameters.AddWithValue("@PType", processtype);           
            myCom.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter myadp = new SqlDataAdapter(myCom);
            myadp.Fill(mydt);
            return mydt;
        }
        
        public static DataTable GetDetailsByNameFromMappingMaster(string empID, int processtype)
        {
            DataTable mydt = LoadBasicComm();
            myCom.Parameters.AddWithValue("@PType", processtype);
            myCom.Parameters.AddWithValue("@Eid", empID);
            SqlDataAdapter myadp = new SqlDataAdapter(myCom);
            myadp.Fill(mydt);
            return mydt;
        }

        public static DataTable GetDetailsByNameFromMappingHistoryMaster(string empID, int processtype)
        {
            DataTable mydt = new DataTable();
            myCom = new SqlCommand();
            myCom.Connection = myCon;
            myCom.CommandText = "SP_ORG_Get_Set_TaskMappingHistory";
            myCom.CommandType = CommandType.StoredProcedure;
            myCom.Parameters.AddWithValue("@PType", processtype);
            myCom.Parameters.AddWithValue("@Eid", empID);
            SqlDataAdapter myadp = new SqlDataAdapter(myCom);
            myadp.Fill(mydt);
            return mydt;
        }
    }
}
